package Leetcode;

public class Leetcode_110 {
    public static int distanceBetweenBusStops(int[] distance, int start, int destination) {
        if(start==destination){
            return 0;
        }
        int dis1=0,p1=start;//顺时针
        while (p1!=destination){
            dis1+=distance[p1];
            p1=(++p1)%distance.length;
        }
        int dis2=0,p2=start;//逆时针
        while (p2!=destination){
            p2=(--p2+distance.length)%distance.length;
            dis2+=distance[p2];
        }
        return Math.min(dis1,dis2);
    }

    public static void main(String[] args) {
        int[] distance = {1,2,3,4};
        int start  = 0, destination = 2;
        System.out.println(distanceBetweenBusStops(distance,start,destination));
    }
}
